package com.edu.controller;

import com.edu.pojo.Student;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * @作者 five-five
 * @创建时间 2021/1/19
 */
@RestController
@Api(tags = "消费者测试")
public class ClientController {
    @Autowired
    private RestTemplate restTemplate;
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<Student> list(){
        ArrayList<Student> studentArrayList = new ArrayList<Student>();
        //调用时,需要把自己也注册到Eureka注册中心去,所以在yml配置中需要小心
//        return restTemplate.getForObject("http://localhost:8762/list",studentArrayList.getClass());//不走注册中心
        return restTemplate.getForObject("http://eureka-privoder/list",studentArrayList.getClass());//走注册中心
    }

    @RequestMapping(value = "/discovery", method = RequestMethod.GET)
    public Object discoveryClient(){
        Object forObject = restTemplate.getForObject("http://eureka-privoder/discovery", Object.class);
        return forObject;//走注册中心
    }
}
